# main()
snippet main
	int main(int argc, const char *argv[])
	{
		${1}
		return 0;
	}
# #include <...>
snippet inc
	#include <${1:stdio}.h>${2}
# #include "..."
snippet Inc
	#include "${1:`Filename("$1.h")`}"${2}
# #ifndef ... #define ... #endif
snippet Def
	#ifndef $1
	#define ${1:SYMBOL} ${2:value}
	#endif${3}
snippet def
	#define 
snippet ifdef
	#ifdef ${1:FOO}
		${2:#define }
	#endif
snippet #if
	#if ${1:FOO}
		${2}
	#endif
# Header Include-Guard
# (the randomizer code is taken directly from TextMate; it could probably be
# cleaner, I don't know how to do it in vim script)
snippet once
	#ifndef ${1:`toupper(Filename('', 'UNTITLED').'_'.system("/usr/bin/ruby -e 'print (rand * 2821109907455).round.to_s(36)'"))`}

	#define $1

	${2}

	#endif /* end of include guard: $1 */
# If Condition
snippet if
	if (${1:/* condition */}) {
		${2:/* code */}
	}
snippet el
	else {
		${1}
	}
# Tertiary conditional
snippet t
	${1:/* condition */} ? ${2:a} : ${3:b}
# Do While Loop
snippet do
	do {
		${2:/* code */}
	} while (${1:/* condition */});
# While Loop
snippet wh
	while (${1:/* condition */}) {
		${2:/* code */}
	}
# For Loop
snippet for
	for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
		${4:/* code */}
	}
# Custom For Loop
snippet forr
	for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
		${5:/* code */}
	}
# Function
snippet fun
	${1:void} ${2:function_name}(${3})
	{
		${4:/* code */}
	}
# Function Declaration
snippet fund
	${1:void} ${2:function_name}(${3});${4}
# Typedef
snippet td
	typedef ${1:int} ${2:MyCustomType};${3}
# Struct
snippet st
	struct ${1:`Filename('$1_t', 'name')`} {
		${2:/* data */}
	}${3: /* optional variable list */};${4}
# Typedef struct
snippet tds
	typedef struct ${2:_$1 }{
		${3:/* data */}
	} ${1:`Filename('$1_t', 'name')`};
# Typdef enum
snippet tde
	typedef enum {
		${1:/* data */}
	} ${2:foo};
# printf
# unfortunately version this isn't as nice as TextMates's, given the lack of a
# dynamic `...`
snippet pr
	printf("${1:%s}\n"${2});${3}
# fprintf (again, this isn't as nice as TextMate's version, but it works)
snippet fpr
	fprintf(${1:stderr}, "${2:%s}\n"${3});${4}
snippet .
	[${1}]${2}
snippet un
	unsigned
	
#######################################################
#This is socket programming snippets,writed by XGuru
#######################################################

#socket include files
snippet incsocket
	#include <sys/types.h>
	#include <sys/socket.h>
	#include <netinet/in.h>
	#include <arpa/inet.h>
	#include <netdb.h>

#ssin = struct sockaddr_in
snippet ssin
	struct sockaddr_in
#SA = sockaddr *
snippet SA
	struct sockaddr *
#addrset
snippet addrset
	${1:serv_addr}.sin_family = ${2:AF_INET};
	${3:serv_addr}.sin_port = ${4:htons(port)};
	${5:serv_addr}.sin_addr.s_addr = ${6:INADDR_ANY};
#setnonblocking
snippet setnonblocking
	fcntl(${1:sockfd},F_SETFL,fcntl(sockfd,F_GETFD,0)|O_NONBLOCK)
#socket
snippet socket
	if((${1:sockfd} = socket(${2:AF_INET},${3:SOCK_STREAM},0)) < 0){
		${4:perror("socket error");}
		${5:exit(1);}
	}
#bind
snippet bind
	if( bind(${1:listenfd},(struct sockaddr *)&${2:server_addr},sizeof(${3:server_addr})) < 0 ){
		${4:perror("bind error");}
		${5:exit(1)};
	}
#listen
snippet listen
	if( listen(${1:sockfd},${2:128}) < 0 ){
		${3:perror("listen error");}
		${4:exit(1);}
	}
#accept
snippet accept
	int ${1:client_len} = sizeof(${2:client_addr});
	if((${3:connfd} = accept (${4:sockfd}, &${5:client_addr}, &${6:client_len})) < 0){
		${7:perror("accept error");}
		${8:exit (1);}
	}
#accept
snippet connect
	if (connect(${1:sockfd},&${2:serv_addr},sizeof(${3:serv_addr})) < 0)
		${4:perror("accept error");}
		${5:exit (1);}
	}
#recvfrom
snippet recvfrom
	recvfrom(${1:int socket}, ${2:void *restrict buffer}, ${3:size_t length},
		${4:int flags}, ${5:struct sockaddr *restrict address},
		${6:socklen_t *restrict address_len})
#sendto
snippet sendto
	sendto(${1:int socket}, ${2:const void *buffer},${3:size_t length}, ${4:int flags},
		${5:const struct sockaddr *to}, ${6:socklen_t address_len});
#write
snippet write
	if( write(${1:fd},${2:buffer},strlen(${3:buffer})) < 0 ){
		${4:perror("write error");}
		${5:exit(1);}
	}
#read
snippet read
	if( read(${1:fd}, ${2:*buf}, ${3:count}) < 0 )
		${4:perror("write error");}
		${5:exit(1);}
	}
#bzero
snippet bzero
	bzero(${1:(char *) &serv_addr},sizeof(${2:serv_addr}));
